/**
 * @author scylla
 * @version V1.0
 * @Project echo-java-base
 * @Title 提莫攻击
 * @Description *
 * @Package lc.mthread
 * @Since 2021/11/12 3:05 下午
 */
package leetcode.mthread.timoattack1;

import java.text.MessageFormat;
import java.util.Arrays;

public class TimoAttack3 {


    public static int findPoisonedDuration(int[] timeSeries, int duration) {
        //中毒总时长  最终的结果
        int poisonedlast = 0;

        int length = timeSeries.length;
        for (int i = 0; i < length; i++) {

            //仅一次攻击
            if (length == 1) {
                poisonedlast += duration;
            }

            //仅两次攻击
            if (length == 2) {
                int sc = timeSeries[1] - timeSeries[0];
                if (sc > duration) {
                    poisonedlast = duration * 2;
                } else {
                    poisonedlast += sc + duration;
                }

            }


        }


        return poisonedlast;
    }

    public static void main(String[] args) {
        int[] timeSeries = {1, 3, 5, 7, 9, 11, 13, 15};
        int duration = 1;
        System.out.println(MessageFormat.format("timeSeries = {0},duration = {1}", Arrays.toString(timeSeries), duration));
        System.out.println(MessageFormat.format("中毒总时长为：{0}", findPoisonedDuration(timeSeries, duration)));
    }
}
